home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 29
/
Volume 29 - JOGO DISK .iso
/
Games
/
jungle_adventure.swf
/
scripts
/
__Packages
/
WalkingObject.as
< prev
Wrap
Text File
|
2006-11-29
|
6KB
|
195 lines
class WalkingObject extends SSObject
{
var classID = SSGlobal.CLSID_MOBILEOBJECT;
var collisionMask = SSGlobal.CLSID_SHAPE | SSGlobal.CLSID_MAINCHAR;
var assetID = "WalkingObject";
var gravity = SSGlobal.GRAVITY;
var walkLeft = true;
var healthValue = -0.2;
var speed = 50;
var immobilized = 0;
var immobilizeTime = 5;
var strength = 250;
var maxWalkableAngle = 0.4;
var collision = false;
var editor_isItem = true;
var editor_name = "WalkingObject";
var editor_args_names = ["walkLeft"];
var editor_args_values = [WalkingObject.prototype.walkLeft];
var editor_args_types = ["boolean"];
var editor_args_options = [null];
var editor_args_descriptions = [""];
var editor_args_mode = [0];
var editor_args_component = ["CheckBox"];
function WalkingObject()
{
super();
}
function onAddToScene()
{
this.getUpdates();
if(this.immobilized)
{
this.immobilized = Math.max(this.immobilized - (this.world.time - this.exitedSceneAt),0);
}
if(this.immobilized)
{
this.target.gotoAndStop(this.currentAnimation);
}
else
{
this.resetAnimation();
}
}
function onRemoveFromScene()
{
this.cancelUpdates();
this.exitedSceneAt = this.world.time;
}
function immobilize()
{
this.velocity.y = -300;
this.velocity.x = 0;
this.contact = null;
GameSound.playSound("enemyhit");
this.setAnimation("Immobile" + (!this.walkLeft ? "Right" : "Left"));
this.immobilized = this.immobilizeTime;
}
function setAnimation(anim)
{
this.target.gotoAndStop(this.currentAnimation = anim);
}
function resetAnimation()
{
this.setAnimation("Walk" + (!this.walkLeft ? "Right" : "Left"));
}
function onCollision(obj)
{
if((obj.classID & 4294901760) == SSGlobal.CLSID_MAINCHAR)
{
if(this.immobilized)
{
return undefined;
}
if(obj.classID == SSGlobal.CLSID_VEHICLE || obj.shield)
{
if(obj.active)
{
this.immobilize();
}
return undefined;
}
if(!obj.active)
{
return undefined;
}
if(!obj.jumpTime && obj.y < this.y)
{
this.immobilize();
obj.velocity.x *= 1.1;
obj.velocity.y *= -0.5;
}
else if(!obj.immune)
{
var _loc3_ = undefined;
obj.shiftHealth(this.healthValue,this);
if(this.walkLeft && obj.x < this.x || !this.walkLeft && obj.x > this.x)
{
this.flip();
}
}
return true;
}
}
function checkIfOnEdge(e)
{
var _loc8_ = e.a;
var _loc2_ = e.normal;
var _loc3_ = this.contact.direction;
var _loc5_ = this;
var _loc6_ = (_loc2_.x * (_loc5_.x - _loc2_.x * this.radius) + _loc2_.y * (_loc5_.y - _loc2_.y * this.radius) - (_loc2_.x * (_loc8_.x + this.contact.shape.x) + _loc2_.y * (_loc8_.y + this.contact.shape.y))) / (- (_loc2_.x * _loc3_.x + _loc2_.y * _loc3_.y));
if(_loc6_ * (!this.walkLeft ? 1 : -1) < ((e.props & 3) != 3 ? this.radius * 2 : 0))
{
if((e.props & 3) == 3)
{
var _loc7_ = Math.abs(_loc6_);
this.moveBy(_loc7_ * _loc3_.x,_loc7_ * _loc3_.y,0);
this.contact = e;
}
else
{
this.flip();
}
this.target._rotation = this.angle = Math.atan2(this.contact.normal.x,- this.contact.normal.y) / 3.141592653589793 * 180;
}
}
function flip()
{
this.walkLeft = !this.walkLeft;
this.resetAnimation();
}
function update(elapsed)
{
if(this.immobilized)
{
if(!(this.immobilized = Math.max(0,this.immobilized - elapsed)))
{
this.contact = null;
this.velocity.y = -200;
this.setAnimation("restore" + (!this.walkLeft ? "Right" : "Left"));
}
}
if(this.contact)
{
if(this.immobilized)
{
this.velocity.x = this.velocity.y = 0;
}
else
{
this.velocity.x = this.contact.direction.x * this.speed * (!this.walkLeft ? 1 : -1);
this.velocity.y = this.contact.direction.y * this.speed * (!this.walkLeft ? 1 : -1);
}
this.checkIfOnEdge(!this.walkLeft ? this.contact.next : this.contact.previous);
}
else
{
this.velocity.y += this.gravity * elapsed;
}
this.collision = false;
this.checkCollisions(elapsed);
if(!this.collision)
{
this.moveBy(this.velocity.x * elapsed,this.velocity.y * elapsed,0);
}
}
function setContact(edge)
{
this.contact = edge;
}
function checkCollision(obj)
{
var _loc2_ = undefined;
switch(obj.classID & 4294901760)
{
case SSGlobal.CLSID_SHAPE:
if(!this.contact && (_loc2_ = SSCollision.sweepSphereToStaticShape(this,obj)))
{
var _loc4_ = this.velocity.__get__length();
var _loc5_ = this.motionDir.dot(_loc2_.normal);
this.setContact(_loc2_.edge);
this.x = _loc2_.point.x;
this.y = _loc2_.point.y;
this.collision = true;
}
break;
case SSGlobal.CLSID_MAINCHAR:
if(SSCollision.sweepSphereToSphere(this,obj,true))
{
return this.onCollision(obj);
}
break;
}
}
}